package com.yaoyou.dao;

import com.yaoyou.model.dataObject.IdRatePair;
import com.yaoyou.model.dataObject.MedicineComment;
import com.yaoyou.model.dataObject.ShopComment;
import com.yaoyou.model.dataObject.ShopCommentExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface ShopCommentMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @SelectProvider(type=ShopCommentSqlProvider.class, method="countByExample")
    int countByExample(ShopCommentExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @DeleteProvider(type=ShopCommentSqlProvider.class, method="deleteByExample")
    int deleteByExample(ShopCommentExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @Delete({
        "delete from SHOP_COMMENT",
        "where COMMENT_ID = #{commentId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String commentId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @Insert({
        "insert into SHOP_COMMENT (COMMENT_ID, SHOP_INFO_ID, ",
        "REMARK, RATE, CREATE_USER_NAME, ",
        "CREATE_TIME, CREATE_USER_ID)",
        "values (#{commentId,jdbcType=VARCHAR}, #{shopInfoId,jdbcType=VARCHAR}, ",
        "#{remark,jdbcType=VARCHAR}, #{rate,jdbcType=INTEGER}, #{createUserName,jdbcType=VARCHAR}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{createUserId,jdbcType=VARCHAR})"
    })
    int insert(ShopComment record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @InsertProvider(type=ShopCommentSqlProvider.class, method="insertSelective")
    int insertSelective(ShopComment record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @SelectProvider(type=ShopCommentSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="COMMENT_ID", property="commentId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="SHOP_INFO_ID", property="shopInfoId", jdbcType=JdbcType.VARCHAR),
        @Result(column="REMARK", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="RATE", property="rate", jdbcType=JdbcType.INTEGER),
        @Result(column="CREATE_USER_NAME", property="createUserName", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="CREATE_USER_ID", property="createUserId", jdbcType=JdbcType.VARCHAR)
    })
    List<ShopComment> selectByExample(ShopCommentExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @Select({
        "select",
        "COMMENT_ID, SHOP_INFO_ID, REMARK, RATE, CREATE_USER_NAME, CREATE_TIME, CREATE_USER_ID",
        "from SHOP_COMMENT",
        "where COMMENT_ID = #{commentId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="COMMENT_ID", property="commentId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="SHOP_INFO_ID", property="shopInfoId", jdbcType=JdbcType.VARCHAR),
        @Result(column="REMARK", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="RATE", property="rate", jdbcType=JdbcType.INTEGER),
        @Result(column="CREATE_USER_NAME", property="createUserName", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="CREATE_USER_ID", property="createUserId", jdbcType=JdbcType.VARCHAR)
    })
    ShopComment selectByPrimaryKey(String commentId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @UpdateProvider(type=ShopCommentSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") ShopComment record, @Param("example") ShopCommentExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @UpdateProvider(type=ShopCommentSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") ShopComment record, @Param("example") ShopCommentExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @UpdateProvider(type=ShopCommentSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(ShopComment record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table SHOP_COMMENT
     *
     * @mbggenerated Thu Jul 28 11:24:57 CST 2016
     */
    @Update({
        "update SHOP_COMMENT",
        "set SHOP_INFO_ID = #{shopInfoId,jdbcType=VARCHAR},",
          "REMARK = #{remark,jdbcType=VARCHAR},",
          "RATE = #{rate,jdbcType=INTEGER},",
          "CREATE_USER_NAME = #{createUserName,jdbcType=VARCHAR},",
          "CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},",
          "CREATE_USER_ID = #{createUserId,jdbcType=VARCHAR}",
        "where COMMENT_ID = #{commentId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(ShopComment record);

    @Select({
            "select *",
            "from SHOP_COMMENT",
            "where SHOP_INFO_ID = #{shopId,jdbcType=VARCHAR}",
            "order by CREATE_TIME desc",
            "LIMIT #{offset},#{limit}"
    })
    List<ShopComment> selectByLimit(@Param("shopId") String commentId, @Param("offset") int offset, @Param("limit") int limit);


    @Select({
            "select SHOP_INFO_ID,AVG(RATE) R",
            "from SHOP_COMMENT",
            "GROUP BY SHOP_INFO_ID",
    })
    @Results({
            @Result(column="SHOP_INFO_ID", property="id", jdbcType=JdbcType.VARCHAR),
            @Result(column="R", property="rate", jdbcType=JdbcType.DECIMAL),
    })
    List<IdRatePair> selectAvgRateList();

}